home *** CD-ROM | disk | FTP | other *** search
/ A Teacher's Guide to the Holocaust / A Teacher's Guide to the Holocaust.iso / data / people / scripts / eleminptclass.js < prev    next >
Text File  |  1999-12-05  |  5KB  |  166 lines

  1. // Copyright 1998,1999 Macromedia, Inc. All rights reserved.
  2.  
  3. //Constructs a multiple choice element
  4. function MM_inpt(theParent, theName, theInitialValue,
  5.                  theExpectedValue, theIsCorrect, theScore) {
  6.   // properties
  7.   this.initialValue = theInitialValue;
  8.   this.value = '';
  9.   this.disabled = true;
  10.   
  11.   this.expectedValue = theExpectedValue;
  12.   this.isCorrect = theIsCorrect;
  13.   this.score = theScore;
  14.   this.selected = false;
  15.   
  16.   this.isRadioList = false;
  17.   
  18.   this._parent = theParent;
  19.   this._name = theName;
  20.   this._obj = '';
  21.   
  22.   this.c = new Array(this); // NOTE: choice info stored on the element.
  23.  
  24.   // member functions
  25.   this.init = MM_inptInit;
  26.   this.reset = MM_inptReset;
  27.   this.enable = MM_inptEnable;
  28.   this.disable = MM_inptDisable;
  29.   this.update = MM_inptUpdate;
  30.   this.setDisabled = MM_inptSetDisabled;
  31.   this.redraw = MM_inptRedraw;
  32.   this.validValue = MM_inptValidValue;
  33.   this.setValue = MM_inptSetValue;
  34.   this.setSelected = MM_inptSetSelected;
  35.   this.changeValue = MM_inptChangeValue;
  36. }
  37.  
  38. // Initializes the element, special case radio lists
  39. function MM_inptInit() {
  40.   var rlist, i, pos=0;
  41.   with (this) { 
  42.     _obj = MM_intFindObject(_parent._self + _name + "Inp");
  43.     if (!_obj) { // assume radio
  44.       rlist = MM_intFindObject(_parent._self + "RadioInp");
  45.       if (rlist && rlist.length != null) {
  46.           for (i in _parent.e) if (i != 'length') // get our element position
  47.             if (_parent.e[i] == this) break; else pos++;
  48.           if (pos < rlist.length) _obj = rlist[pos];  // get radio at same position
  49.           isRadioList = true;
  50.   } } } 
  51. }
  52.  
  53. //Resets the element
  54. function MM_inptReset() {
  55.   var isChanged = '';
  56.   with (this) {
  57.     isChanged = (value != initialValue);
  58.     value = initialValue;
  59.     _parent.disabled ? disable() : enable();
  60.     validValue();
  61.     redraw();
  62.     if (isChanged && this.onChange != null) onChange(_parent._self+_name, value);
  63.   }
  64. }
  65.  
  66. //Enables the element
  67. function MM_inptEnable() {
  68.   if (this._obj) with (this) {
  69.     disabled = false;
  70.     redraw();
  71.   }
  72. }
  73.  
  74. //Calls the approppriate disable or enable function
  75. function MM_inptSetDisabled(theDisabled) {
  76.   if (theDisabled) this.disable();
  77.   else this.enable();
  78. }
  79.  
  80. //Disables the element
  81. function MM_inptDisable() {
  82.   this.disabled = true;
  83.   this.redraw();
  84. }
  85.  
  86. //Called by onClick event to update this elements value
  87. function MM_inptUpdate() {
  88.   var noJudge = false;
  89.   with (this) {
  90.     if (disabled) {
  91.       if (!isRadioList) 
  92.         redraw();
  93.       else
  94.         for (var i in _parent.e) if (i != 'length')
  95.           _parent.e[i].redraw();
  96.       return;
  97.     }
  98.   
  99.     if (_obj.checked != null) {
  100.       if (isRadioList && value == _obj.checked) noJudge = true; //IE3.0 oddity
  101.       changeValue((_obj.checked) ? true : false);  //IE3.0 oddity
  102.     } else
  103.       changeValue(_parent.allowMultiSel ? !value : true);
  104.   
  105.     // call the parent's update
  106.     _parent.update(noJudge);
  107.   }
  108. }
  109.  
  110. //Sets the checked state of the form element
  111. function MM_inptRedraw() {
  112.   if (this._obj) with (this) {
  113.     if (_obj.disabled != null) _obj.disabled = disabled;
  114.     if (isRadioList) {
  115.       if (value) _obj.checked = true;
  116.     } else if (_obj.checked != null) _obj.checked = value;
  117.   }
  118. }
  119.  
  120. //Checks the value with the expectedValue
  121. function MM_inptValidValue() {
  122.   this.selected = (this.value == this.expectedValue);
  123.   return this.selected;
  124. }
  125.  
  126. //Internal routine for changing element value
  127. function MM_inptChangeValue(theValue) {
  128.   var i, isChanged = '', isReset = '';
  129.   with (this) {
  130.     isChanged = (value != theValue);
  131.     if (!_parent.allowMultiSel || isRadioList || _obj.type == 'radio') {
  132.       value = theValue;
  133.       for (i in _parent.e) if (i != 'length') with (_parent) {
  134.         if (e[i] != this) {
  135.           isReset = (e[i].value != false);
  136.           e[i].value = false;
  137.         }
  138.         e[i].validValue();
  139.         e[i].redraw();
  140.         if (e[i] != this && isReset && e[i].onChange != null)
  141.           e[i].onChange(e[i]._parent._self+e[i]._name, e[i].value);
  142.       }
  143.     } else {
  144.       value = theValue;
  145.       validValue();
  146.       redraw();
  147.     }
  148.     if (isChanged && this.onChange != null) onChange(_parent._self+_name, value);
  149.   }
  150. }
  151.  
  152. //Sets the state of the element to the given value
  153. function MM_inptSetValue(theValue) {
  154.   with (this) {
  155.     changeValue(theValue);
  156.     _parent.update(true); // update int, but don't judge
  157.   }
  158. }
  159.  
  160. //Sets this element to its selected state
  161. function MM_inptSetSelected(theSelected) {
  162.   if (theSelected)
  163.     this.setValue(this.expectedValue);
  164.   else
  165.     this.setValue(!this.expectedValue);
  166. }